package demo.mysql.java.connectivity;

import java.sql.*;

public class ProcessDB 
{
	public ProcessDB(){}
	
	public boolean Execute_DB(Connection conn, String query)
	{
		Statement st;
		int ir=0;
		try
		{
			st = conn.createStatement();
			ir = st.executeUpdate(query);
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		
		if(ir>0) return true;
		return false;
	}
		
	public ResultSet Get_DB(Connection conn, String query)
	{
		Statement st;
		ResultSet rs = null;
		try
		{
			st = conn.createStatement();
			rs = st.executeQuery(query);
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		return rs;
	}
	public static void main(String[] args) {
		ConnectToMySQLSimple connect = new ConnectToMySQLSimple();
		Connection conn = null;
		conn = connect.Open_ConnectDB();
		//connect.Close_ConnectDB(conn);
		ProcessDB process = new ProcessDB();
		Query queryString = new Query(); 
		String[] table = {"Nouvel"};
		String[] fields = { "idNouvel", "Description" };
		
		String t = queryString.Query_Select(table,fields, "");
		ResultSet result = process.Get_DB(conn, t);
		try{
			while (result.next()) {
			   System.out.println("NouvelID: " + result.getString(1));
			   System.out.println("Description: " + result.getString(2));
			}
		}
		catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
	}
}